package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.FeedbackDetailsApi;
import com.jjb.www.http.glide.GlideApp;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class BackDetailsAdapter extends AppAdapter<FeedbackDetailsApi.Bean.ListDTO> {
    private ImgListAdapter imgListAdapter;
    public BackDetailsAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeImageView mImgHead;
        private ShapeTextView mTvName;
        private WrapRecyclerView mRvImg;
        private ShapeTextView mTvTime;



        private ViewHolder() {
            super(R.layout.item_feedback_details);
            mImgHead = findViewById(R.id.img_head);
            mTvName = findViewById(R.id.tv_name);
            mRvImg = findViewById(R.id.rv_img);
            mTvTime = findViewById(R.id.tv_time);
            mRvImg.setLayoutManager(new GridLayoutManager(getContext(),3));
            imgListAdapter = new ImgListAdapter(getContext());
            mRvImg.setAdapter(imgListAdapter);
        }

        @Override
        public void onBindView(int position) {
            FeedbackDetailsApi.Bean.ListDTO bean = getItem(position);
            GlideApp.with(getContext())
                    .load(bean.getAvatar_id())
                    .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                    .into(mImgHead);
            mTvName.setText(bean.getContent());
            mTvTime.setText(bean.getCreate_time());
            imgListAdapter.setData(bean.getImg());
        }
    }
}